<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
     * {
      box-sizing: border-box;
    }

    .box {
      width: 560px;
      height: 400px;
      background-color: pink;
      position: relative;
    }

    .img1 {
      width: 100%;
      height: 320px;
      display: block;
    }
    
    .left{
        position: absolute;
        top: 120px;
    }
    .right{
        position: absolute;
        top: 120px;
        right: 0px;
    }

    .bottom {
      height: 80px;
      background-color: green;
      padding: 10px 10px 0 10px;
    }

    .bottom p {
      margin: 0;
      color: white;
      margin-bottom: 10px;
    }

    .bottom-ul {
      width: 150px;
      display: flex;
      list-style: none;
      margin: 0;
      padding: 0;
      justify-content: space-between;
      align-items: center;
    }

    .bottom-ul li {
      width: 8px;
      height: 8px;
      margin: 4px;
      border-radius: 50%;
      background: #fff;
      opacity: 0.4;
      cursor: pointer;
    }
    li.lihover {
      width: 12px;
      height: 12px;
      opacity: 1;
    }
  </style>

</head>
<body>
    
    
    <div class="box">
    <img src="../images/1.webp" class="img1">
    <img src=".//left.png" class="left">
    <img src="./right.png" class="right">
    <div class="bottom">
      <p>对人类来说会不会太超前了？</p>
      <ul class="bottom-ul">
        <li class="lihover"></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
      </ul>
    </div>
    </div>



     <script>

    const sliderData = [
      { url: '../images/1.webp', title: '对人类来说会不会太超前了？', color: 'rgb(100, 67, 68)' },
      { url: '../images/2.webp', title: '开启剑与雪的黑暗传说！', color: 'rgb(43, 35, 26)' },
      { url: '../images/3.webp', title: '真正的jo厨出现了！', color: 'rgb(36, 31, 33)' },
      { url: '../images/4.webp', title: '快来分享你的寒假日常吧~', color: 'rgb(139, 98, 66)' },
      { url: '../images/5.webp', title: '李玉刚：让世界通过B站看到东方大国文化', color: 'rgb(67, 90, 92)' },
      { url: '../images/6.webp', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },
      { url: '../images/7.webp', title: '一站式解决你的电脑配置问题！！！', color: 'rgb(53, 29, 25)' },
      { url: '../images/8.webp', title: '谁不想和小猫咪贴贴呢！', color: 'rgb(99, 72, 114)' },
    ]

    const divv = document.querySelector('.box')
    const img1 = document.querySelector('.img1')
    const left = document.querySelector('.left')
    const right = document.querySelector('.right')
    const p = document.querySelector('p')
    const bgc = document.querySelector('.bottom')
    let i = 0
     function fn(){
      img1.src = sliderData[i].url
      p.innerHTML = sliderData[i].title
      bgc.style.backgroundColor = sliderData[i].color

      const scli = document.querySelector('ul .lihover')
      scli.classList.remove('lihover')

      const li = document.querySelector(`li:nth-child(${i+1})`)
      li.classList.add('lihover')
     }
    //左按钮
        left.addEventListener('click',function(){
            i = i-1
            if(i<0){
                i = (sliderData.length-1)
            }
            fn()
        })
        
        //右按钮
        right.addEventListener('click',function(){
            i = i+1
            if(i===sliderData.length){
              i = 0
            }
            fn()
        })

        time = setInterval(function(){
          right.click()
        },1000)

        //停止
        divv.addEventListener('mouseenter',function(){
            clearInterval(time)           
        })

        //启动
        divv.addEventListener('mouseleave',function(){
          if(time) clearInterval(time)
            time = setInterval(function(){
                right.click()
            },1000)
        })
  </script>

</body>
</html>